﻿using System.Collections.ObjectModel;
using System.Linq;
using Tisbi.LawFirm.DAL.Models;

namespace Tisbi.LawFirm.UI.ViewModel
{
    public class CourtCRUDViewModel : BaseCRUDItemViewModel<Court>
    {
        public CourtCRUDViewModel(Court model) : base(model)
        {
        }


        private ObservableCollection<District> _districts;
        public ObservableCollection<District> Districts
        {
            get { return _districts; }
            set
            {
                _districts = value;
                if (Model.District != null)
                {
                    SelectedDistrict = Districts.First(x => x.Id == Model.District.Id);
                }
                RaisePropertyChanged(() => Districts);
            }
        }

        public District SelectedDistrict
        {
            get { return Model.District; }
            set
            {
                Model.District = value;
                RaisePropertyChanged(() => SelectedDistrict);
            }
        }

        public string Title
        {
            get { return Model.Title; }
            set
            {
                Model.Title = value;
                RaisePropertyChanged(() => Title);
            }
        }

        public override string Error
        {
            get
            {
                return this["Title"];
            }
        }

        public override string this[string columnName]
        {
            get
            {
                string result = string.Empty;
                switch (columnName)
                {
                    case "Title":
                        if (string.IsNullOrWhiteSpace(Model.Title)) result = "Поле 'Название' обязательное";
                        break;
                }
                return result;
            }
        }
    }
}
